{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=3071
  Verdict: Accepted
}
uses SysUtils, Math;
 
var
	n,ans,mx:int64;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
mx:=n;
ans:=-round(1e9);
while n<>0 do begin
	read(n);
	if n>=mx then begin
		ans:=mx;
		mx:=n;
	end else 
	if n>=ans then ans:=n;
end;
write(ans);
end.